const _ = require("lodash");
const group = require("./group.js");

// ✅ 步骤1：处理每组分组
const allGroups = Object.entries(group).map(([name, subgroups]) => {
  // 子组内部排序
  const sortedSubgroups = subgroups.map(sub => _.sortBy(sub));

  // 子组整体排序（忽略ABC顺序）
  const normalizedGroup = _.sortBy(sortedSubgroups, (arr) => arr.join(","));

  return {
    name,
    normalizedKey: normalizedGroup.map(arr => arr.join(",")).join("||"),
    normalizedGroup,
  };
});

// ✅ 步骤2：分组统计重复
const groupMap = {}; // key: normalizedKey, value: [group names]

allGroups.forEach(({ name, normalizedKey, normalizedGroup }) => {
  if (!groupMap[normalizedKey]) {
    groupMap[normalizedKey] = [];
  }
  groupMap[normalizedKey].push(name);
});

// ✅ 步骤3：输出重复项
let hasDuplicate = false;
console.log("🔍 检查重复分组（忽略子组顺序与顺序内排序）：\n");

Object.entries(groupMap).forEach(([key, names]) => {
  if (names.length > 1) {
    hasDuplicate = true;
    console.log(`⚠️ 重复分组: ${names.join(", ")}`);
    console.log(`内容（已归一化）：`);
    const groups = key.split("||");
    groups.forEach((line, idx) => {
      console.log(`  子组 ${idx + 1}：[${line}]`);
    });
    console.log("");
  }
});

if (!hasDuplicate) {
  console.log("✅ 所有分组都是唯一的（忽略子组顺序）");
}
